package com.iot.iotplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.iot.iotplus.base.Result;
import com.iot.iotplus.base.ResultCode;
import com.iot.iotplus.entity.Area;
import com.iot.iotplus.mapper.AreaMapper;
import com.iot.iotplus.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaMapper areaMapper;
    @Override
    public Result<?> getAreaList() {
        LambdaQueryWrapper<Area> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Area::getPid,0);
        List<Area> list = areaMapper.selectList(wrapper);
        list = list.stream().map(item -> {
            item.setAreas(areaMapper.queryByAreas(item.getCode()));
            return item;
        }).collect(Collectors.toList());
        return new Result<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), list);
    }

}
